<template>
    <div class="listDiv">
        <div class="searchDiv">
            <el-select v-model="obj.req.type" placeholder="类别" class="search_select" clearable>
                <el-option v-for="(item,index) in obj.type_all" :key="index" :label="item.name" :value="item.id" />
            </el-select>
            <el-select v-model="obj.req.source" placeholder="来源" class="search_select" clearable>
                <el-option v-for="(item,index) in globalData.sourceAry" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <DateRange v-model:start="obj.req.starttime" v-model:end="obj.req.endtime" sph="发布时间" />
            <el-input clearable placeholder="匹配标题" v-model="obj.req.key" class="search_key ml5" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <div class="searchRight">
                <!-- <span class="btn add" @click="add">添加资讯</span> -->
            </div>
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="mw300">标题</li>
                <li class="">企业</li>
                <li class="wcen">类别</li>
                <!-- <li class="li3">接收方</li> -->
                <li class="mw200 wcen">发布时间</li>
                <li class="">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="mw300">
                        <el-tooltip class="box-item" effect="dark" :content="x.title" placement="top-start" :disabled="x.title.length<17">
                            <div class="lineOne pointer">{{x.title}}</div>
                        </el-tooltip>
                    </li>
                    <li class="">{{x.companyname}}</li>
                    <li class="wcen">
                        <div class="label-btn-primary">{{x.typename}}</div>
                    </li>
                    <!-- <li class="li3">{{x.target}}</li> -->
                    <li class="mw200 wcen">{{x.intime}}</li>
                    <li class="">
                        <DelConfirm class="" isclass="edit_btn" buttontype="success" @yesClick="del(x,1)" @noClick="del(x,2)" title="确认要审核通过吗？" text="审核" yes="通过" no="拒绝" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import DateRange from '@/components/date_range.vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    import { ElMessageBox } from 'element-plus'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            type: "",
            source: "",
            starttime:"",
            endtime:"",
            // starttime:proxy.$utils.dateAddDay(new Date(), -7, "yyyy-MM-dd"),
            // endtime:proxy.$utils.dateFormat(new Date(), "yyyy-MM-dd"),
        },
        type_all: []
    });
    let init_befor = async () => {
        obj.type_all = await proxy.$utils.getNewsType(proxy)
    }
    init_befor()
    let init = () => {
        proxy.$ajax({
            url: '/examine/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let del = (x,v) => {
        if(v==2){
            ElMessageBox.prompt('拒绝原因', '拒绝', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                inputPlaceholder: '请输入审核原因',
                inputErrorMessage: 'Invalid Email',
            }).then(({ value }) => {
                examineverify(x.id,v,value)
            }).catch(() => {})
        }else{
            examineverify(x.id,v)
        }
    }

    const examineverify = (id,v,refuse)=>{
        console.log(refuse);
        // return
        proxy.$ajax({
            url: '/examine/verify',
            data: { id: id , verify_state: v,refuse:refuse||''},
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("审核成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { width:100px!important; }
    .search_key { width:160px!important; }
    #tb ul li.li2 { width: 100px; }
    #tb ul li.li3 { width: 135px; }
    #tb ul li.li4 { width: 165px; }
</style>